package org.devocean.groupbuying.web.frontend.displaybeans;

import org.devocean.groupbuying.domain.Article;
import org.devocean.groupbuying.domain.Discount;
import org.devocean.groupbuying.domain.Formula;
import org.devocean.groupbuying.domain.Merchant;
import org.devocean.groupbuying.domain.Plan;
import org.devocean.groupbuying.domain.Promotion;

public class PlanBean {

	private Article article;
	private Article planArticle;
	private String mediaFilePath;
	private Plan plan;
	private Promotion promotion;
	private Merchant merchant;
	private String merchantMediaFilePath;
	private Formula formula;

	public PlanBean(Plan plan) {
		this.setPlanArticle(plan.getArticlesLocalization().getArticles()
				.iterator().next());
		this.article = plan.getProduct().getArticlesLocalization()
				.getArticles().iterator().next();
		this.mediaFilePath = plan.getProduct().getArticlesLocalization()
				.getMediaLocalizations().iterator().next().getMediaFilePath();
		this.plan = plan;
		this.merchant = plan.getProduct().getMerchant();
		this.mediaFilePath = plan.getProduct().getMerchant()
				.getArticlesLocalization().getMediaLocalizations().iterator()
				.next().getMediaFilePath();
	}

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}

	public String getMediaFilePath() {
		return mediaFilePath;
	}

	public void setMediaFilePath(String mediaFilePath) {
		this.mediaFilePath = mediaFilePath;
	}

	public Plan getPlan() {
		return plan;
	}

	public void setPlan(Plan plan) {
		this.plan = plan;
	}

	public Merchant getMerchant() {
		return merchant;
	}

	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}

	public String getMerchantMediaFilePath() {
		return merchantMediaFilePath;
	}

	public void setMerchantMediaFilePath(String merchantMediaFilePath) {
		this.merchantMediaFilePath = merchantMediaFilePath;
	}

	public Article getPlanArticle() {
		return planArticle;
	}

	public void setPlanArticle(Article planArticle) {
		this.planArticle = planArticle;
	}

	public Formula getFormula() {
		try {
			this.formula = plan.getFormulas().iterator().next();
			for (Formula f : plan.getFormulas()) {
				if (f.getPrice() < formula.getPrice()) {
					formula = f;
				}
			}
			return formula;
		} catch (Exception e) {
			return null;
		}

	}

	public void setFormula(Formula formula) {
		this.formula = formula;
	}

	public Promotion getPromotion() {
		if (plan.getPromotions().isEmpty()) {
			return null;
		} else {
			return plan.getPromotions().iterator().next();
		}

	}

	public void setPromotion(Promotion promotion) {
		this.promotion = promotion;
	}

}
